<script setup name="category">
import { useRouter } from 'vue-router';
import { useStore } from 'vuex';

const router = useRouter();
const store = useStore();

// 轮廓图
store.dispatch('homebanner/upHomeBanner');

const homebannerList = computed(() => store.state.homebanner.homebannerList);
const homebannerValue = computed(() => JSON.parse(JSON.stringify(homebannerList.value)));

const categoryList = computed(() => store.state.category.categoryList);
// const categoryValue = computed(() => JSON.parse(JSON.stringify(categoryList.value)));

</script>

<template>
  <div class="conter">
    <!-- 轮播图 -->
    <div class="slideshow wapper">
      <el-carousel trigger="click" interval="1000" height="500px">
        <el-carousel-item v-for="item in homebannerValue" :key="item.id">
          <img :src="item.imgUrl" alt="">
        </el-carousel-item>
      </el-carousel>
    </div>
    <!-- 分类 -->
    <div class="classify wapper">
      <h3>全部分类</h3>
      <div class="box" v-for="item of categoryList.children" :key="item.id">
        <div><img :src="item.picture"/></div>
        <div>{{ item.name }}</div>
      </div>
    </div>
    <!-- 二级分类 -->
    <div class="reclassify wapper">
      <div class="boxone" v-for="item of categoryList.children" :key="item.id">
        <span>
          查看全部
          <i><el-icon><ArrowRight /></el-icon></i>
        </span>
        <h3>- {{ item.name }} -</h3>
        <p>温暖柔软，品质之选</p>
        <div class="vessel">
          <div class="boxtwo" v-for="item of item.goods" :key="item.id">
            <img :src="item.picture" alt="" />
            <p>{{ item.name }}</p>
            <p>{{ item.desc }}</p>
            <p>¥{{ item.price }}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scope>
// 版心
.wapper {
  margin: 0 auto;
  width: 1240px;
}
// 容器
.conter {
  background-color: #f5f5f5;
  // 轮播图
  .slideshow {
    padding-top: 80px;
    padding-bottom: 20px;

    .el-carousel__button {
    border-radius: 50%;
    width: 10px;
    height: 10px;
    background-color: #fff;
    }
  }
  // 分类
  .classify {
    height:260px;
    background-color: #fff;

    h3 {
      margin: 0;
      font-size: 28px;
      color: #666;
      font-weight: 400;
      text-align: center;
      line-height: 100px;
    }

    .box {
      display: inline-block;
      text-align: center;
      padding-left: 70px;

      &:hover {
        color: #27ba9b;
        cursor: pointer;
      }
    }

    img {
      height: 100px;
      width: 100px;
    }
  }
}
// 二级分类
.reclassify {
  margin-top: 20px;
  // background-color: #f5f5f5;
  .boxone {
    background-color: #fff;
    margin-bottom: 20px;

    span {
      display: flex;
      justify-content: flex-end;
      color: #999999;
      text-decoration: none;
      padding: 20px 20px 0px 0px;
      &:hover {
        cursor: pointer;
      }
    }

    i {
      transform: translateY(1px);
    }

    h3 {
      transform: translateY(-40px);
      font-size: 28px;
      margin: 0;
      color: #666;
      font-weight: 400;
      text-align: center;
      line-height: 100px;
    }

    p {
        margin: 0;
        text-align: center;
        color: #999;
        font-size: 20px;
        transform: translateY(-60px);
      }

      .vessel {
        margin-left: 70px;
        transform: translateY(-20px);
        .boxtwo {
          display: inline-block;
          text-align: center;
          width: 220px;
          height: 300px;
          transition: all 0.2s;

          &:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 80px rgba(48, 49, 51, 0.15);
            cursor: pointer;
          }

        img {
          padding-top: 20px;
          height: 160px;
          width: 160px;
        }

        p {
          margin: 0 auto;
          text-align: center;
          font-size: 16px;
          color: black;
          padding-top: 70px;
          width: 160px;
          /* 有限的空间才能有溢出的可能 */
          overflow: hidden;
          -webkit-line-clamp: 1;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          word-break: break-all;
          line-break: anywhere;
        }

        p:nth-child(3) {
          font-size: 14px;
          color: #999;
          padding-top:8px;
        }
        p:last-child {
          color: #cf4444;
          font-size: 20px;
          padding-top: 10px;
        }
      }
    }
  }
}
  </style>
